home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F18452_Books.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2001-09-24  |  2.5 KB  |  64 lines

  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  3. <xsl:output method="html" encoding="ISO-8859-1" indent="yes"/>
  4. <!-- Group books by whether the title contains given key words -->
  5. <xsl:key name="book-group" match="book" use="number(contains(title,'XSL')) * 3"/>
  6. <xsl:key name="book-group" match="book" use="number(contains(title,'ASP')) * 2"/>
  7. <xsl:key name="book-group" match="book" use="number(contains(title,'Java')) * 1"/>
  8. <xsl:key name="book-no-group" match="book" use="number(contains(title,'XSL')) + number(contains(title,'ASP')) + number(contains(title,'Java'))"/>
  9.  
  10. <xsl:template match="/">
  11.     <html>
  12.         <head>
  13.             <title>Books by interest priority</title>
  14.         </head>
  15.         <body>
  16.             <xsl:call-template name="book-table">
  17.                 <xsl:with-param name="title">Books about XSL</xsl:with-param>
  18.                 <xsl:with-param name="book-group">book-group</xsl:with-param>
  19.                 <xsl:with-param name="book-group-id">3</xsl:with-param>
  20.             </xsl:call-template>
  21.             <xsl:call-template name="book-table">
  22.                 <xsl:with-param name="title">Books about ASP</xsl:with-param>
  23.                 <xsl:with-param name="book-group">book-group</xsl:with-param>
  24.                 <xsl:with-param name="book-group-id">2</xsl:with-param>
  25.             </xsl:call-template>
  26.             <xsl:call-template name="book-table">
  27.                 <xsl:with-param name="title">Books about Java</xsl:with-param>
  28.                 <xsl:with-param name="book-group">book-group</xsl:with-param>
  29.                 <xsl:with-param name="book-group-id">1</xsl:with-param>
  30.             </xsl:call-template>
  31.             <xsl:call-template name="book-table"/>
  32.         </body>
  33.     </html>
  34. </xsl:template>
  35.  
  36. <xsl:template match="book">
  37.     <tr>
  38.         <td><xsl:value-of select="title"/></td>
  39.         <td><xsl:value-of select="author"/></td>
  40.         <td><xsl:value-of select="@isbn"/></td>
  41.         <!-- show position of element in original xml -->
  42.         <td align="right"><xsl:value-of select="count(preceding-sibling::book)+1"/></td>
  43.     </tr>
  44. </xsl:template>
  45.  
  46. <xsl:template name="book-table">
  47.     <xsl:param name="title" select="'Other Books'"/>
  48.     <xsl:param name="book-group" select="'book-no-group'"/>
  49.     <xsl:param name="book-group-id" select="number(0)"/>
  50.     <h3><xsl:value-of select="$title"/></h3>
  51.     <table border="1" width="100%">
  52.         <tr>
  53.             <th width="60%">Title</th>
  54.             <th width="25%">Author</th>
  55.             <th>ISBN</th>
  56.             <th>Item No.</th>
  57.         </tr>
  58.         <xsl:apply-templates select="key($book-group,$book-group-id)">
  59.             <xsl:sort select="title"/>
  60.         </xsl:apply-templates>
  61.     </table>
  62. </xsl:template>
  63.  
  64. </xsl:stylesheet>